$(function () {
    getStoragename();
})

//获取所有仓库的名字并注入
function getStoragename() {
    $.ajax({
        type:"post",
        url:"/OutBoundManage/getStoragename",
        data:{},
        dataType:"json",
        success:function(r){
            if (r!= null){
                var t="<option>请选择</option>";
                for (var i=0;i < r.length;i++){
                    t += "<option>"+r[i]+"</option>\n"
                }
                $(".dfselect").html(t);
            }
        },
        error:function (r) {
            alert("!!!")
        }
    })
}

function querentianjiaOutBound() {
    var orderid = $(".forminfo>li:nth-child(1)>input").val();
    var storagename = $(".forminfo>li:nth-child(2)>select").val();
    var outboundtime = $(".forminfo>li:nth-child(3)>input").val();
    var outboundman = $(".forminfo>li:nth-child(4)>input").val();

    if(storagename=="请选择"){
        alert("仓库还未选择 请重新确认！");
    }else if(outboundtime==""){
        alert("出库时间未确定 请重新确认！");
    }else if(orderid==""){
        alert("订单号未确定 请重新确认！");
    }else{
        $.ajax({
            type:"post",
            url:"/OutBoundManage/checkAddOrder",
            data:{orderid:orderid},
            dataType:"json",
            success:function(r){
                if(r==null){
                    alert("订单审核未通过 请重新确认订单！");
                }else if(r.ddstate==0){
                    alert("订单已经出库 请重新确认订单！");
                }else{
                    $.ajax({
                        type:"post",
                        url:"/OutBoundManage/addOutBound",
                        data:{orderid:orderid,storagename:storagename,outboundtime:outboundtime,outboundman:outboundman},
                        dataType:"json",
                        success:function(r){
                            alert("添加出库记录成功！即将返回出库管理界面。。");
                            location.href="deliveryList.html";
                        },
                        error:function (r) {
                            alert("!!!")
                        }
                    })
                    }
                },
            error:function (r) {
                alert("!!!")
            }
        })
    }

}

function toOrderpage(n) {
    var orderid = $(n).html();
    sessionStorage.removeItem("orderid")
    sessionStorage.setItem("orderid",JSON.parse(orderid));

}